package indi.h.devmg.acquisition.snmp.beans;

import org.snmp4j.PDU;
import org.snmp4j.security.AuthMD5;
import org.snmp4j.security.PrivDES;
import org.snmp4j.security.SecurityLevel;
import org.snmp4j.security.UsmUser;
import org.snmp4j.smi.OID;
import org.snmp4j.smi.OctetString;

import indi.h.devmg.acquisition.snmp.SnmpVersion;

/**
 * snmp配置参数类
 * 
 * @author hdy
 *
 */
public class SnmpParam implements Cloneable {
	/**
	 * 对象负责,减轻配置
	 */
	public SnmpParam clone() {
		SnmpParam s = null;
		try {
			s = (SnmpParam) super.clone();
		} catch (CloneNotSupportedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return s;
	}

	// snmp版本
	private SnmpVersion version = SnmpVersion.V2C;
	// 查询的oid数组
	private OID[] oids;
	// 设置ip地址
	private String ip;
	// 连接类型
	private String connectType = "udp";
	// 连接端口
	private int port = 161;
	// snmpV3的用户
	private UsmUser v3User = new UsmUser(new OctetString("MD5DES"), AuthMD5.ID,
			new OctetString("MD5DESUserAuthPassword"), PrivDES.ID, new OctetString("MD5DESUserPrivPassword"));
	// v3加密方式
	private OctetString v3Code = new OctetString("MD5DES");
	// 超时时间
	private int timeOut = 1000;
	// 重发次数
	private int retries = 2;
	// 团体名
	private OctetString community = new OctetString("public");
	// get模式默认获取方式
	private Integer pduType = PDU.GET;
	// 是否同步运行
	private boolean isSync = false;
	// walk模式获取数据长度
	private Integer maxPduSize;
	// walk模式的最低级查询oid
	private OID lowerItem;
	// walk模式最高位查询oid
	private OID upperItem;
	// snmpV3安全等级
	private Integer securityLevel = SecurityLevel.AUTH_PRIV;
	// walk模式用户的对象
	private Object userObject;

	public SnmpVersion getVersion() {
		return version;
	}

	public void setVersion(SnmpVersion version) {
		this.version = version;
	}

	public OID[] getOids() {
		return oids;
	}

	public void setOids(OID[] oids) {
		this.oids = oids;
	}

	public void setOids(String... strOids) {
		this.oids = new OID[strOids.length];
		int i = 0;
		for (String s : strOids) {
			this.oids[i] = new OID(s);
			i++;
		}
	}

	public UsmUser getV3User() {
		return v3User;
	}

	public void setV3User(UsmUser v3User) {
		this.v3User = v3User;
	}

	public OctetString getV3Code() {
		return v3Code;
	}

	public void setV3Code(OctetString v3Code) {
		this.v3Code = v3Code;
	}

	public void setV3Code(String v3Code) {
		this.v3Code = new OctetString(v3Code);
	}

	public int getTimeOut() {
		return timeOut;
	}

	public void setTimeOut(int timeOut) {
		this.timeOut = timeOut;
	}

	public int getRetries() {
		return retries;
	}

	public void setRetries(int retries) {
		this.retries = retries;
	}

	public String getCommunityName() {
		return community.getSyntaxString();
	}

	public OctetString getCommunity() {
		return community;
	}

	public void setCommunity(OctetString community) {
		this.community = community;
	}

	public void setCommunity(String s) {
		this.community = new OctetString(s);
	}

	public Integer getPduType() {
		return pduType;
	}

	public void setPduType(Integer pduType) {
		this.pduType = pduType;
	}

	public Integer getMaxPduSize() {
		return maxPduSize;
	}

	public void setMaxPduSize(Integer maxPduSize) {
		this.maxPduSize = maxPduSize;
	}

	public OID getLowerItem() {
		return lowerItem;
	}

	public void setLowerItem(OID lowerItem) {
		this.lowerItem = lowerItem;
	}

	public void setLowerItem(String lowerItem) {
		this.lowerItem = new OID(lowerItem);
	}

	public OID getUpperItem() {
		return upperItem;
	}

	public void setUpperItem(OID upperItem) {
		this.upperItem = upperItem;
	}

	public void setUpperItem(String upperItem) {
		this.upperItem = new OID(upperItem);
	}

	public boolean isSync() {
		return isSync;
	}

	public void setSync(boolean isSync) {
		this.isSync = isSync;
	}

	public Integer getSecurityLevel() {
		return securityLevel;
	}

	public void setSecurityLevel(Integer securityLevel) {
		this.securityLevel = securityLevel;
	}

	public Object getUserObject() {
		return userObject;
	}

	public void setUserObject(Object userObject) {
		this.userObject = userObject;
	}

	public String getIp() {
		return ip;
	}

	public void setIp(String ip) {
		this.ip = ip;
	}

	public String getConnectType() {
		return connectType;
	}

	public void setConnectType(String connectType) {
		this.connectType = connectType;
	}

	public int getPort() {
		return port;
	}

	public void setPort(int port) {
		this.port = port;
	}

	public String getSnmpUrl() {
		return connectType + ":" + ip + "/" + port;
	}

}
